import bean.BeanDefinition;
import bean.DefaultBeanDefinition;
import bean.DefaultBeanFactory;
import com.test.beans.UserService;
import com.test.beans.UserServiceImpl;

public class TestRegistration {
    public static void main(String[] args) {
        DefaultBeanFactory factory = new DefaultBeanFactory();

        // 创建Bean定义
        BeanDefinition userDefinition = new DefaultBeanDefinition(UserServiceImpl.class);
        boolean validate = userDefinition.validate();
        if (!validate) {
            throw new RuntimeException("beanDefinition is invalid");
        }
        userDefinition.setScope(BeanDefinition.SCOPE_SINGLETION);

        // 注册到容器
        factory.registerBeanDefinition("userService", userDefinition);

        // 获取实例
        UserService userService = (UserService) factory.getBean("userService");
        System.out.println(userService.getUserName());
    }
}
